# 测试类
# jWt原理测试
# import json, base64,  time, hashlib

# # 头部信息
# heard_data = {'typ': 'jwt', 'alg': 'Hs256'}
# # 将字典格式转成字符串
# # json.dumps(heard_date)
# # 将字符串转成字节对象
# head = base64.b64encode(json.dumps(heard_data).encode()).decode()
# # print(head)
#
#
# # 载荷部分：payload
# iat = int(time.time())
#
# payload_data = {
#     "sub": "admin",
#     "exp": iat + 60 * 60,
#     "iat": iat,
#     "name": "superUser",
#     "user_id": 1,
#     "admin": True,
#     "acc_password": "sjsjkhnuveoviovksvosuvjjvODJVHoiqvoiernveoivs",
# }
#
# payload = base64.b64encode(json.dumps(payload_data).encode()).decode()
# # print(payload)
#
# # 第三部分：签证
# secret = 'django-insecure--mp*@emm7f2u+szcx+r$3aqd_#+vw5am&ojfw_*8_mhq6ey45%'
# data = head + payload + secret
# hs256 = hashlib.sha256()
# # 传入数据，并修改编码格式
# hs256.update(data.encode('utf-8'))
# # 获取最终的加密字符串
# signtrue = hs256.hexdigest()
# # print(signtrue)
#
# # 最终jwt数据
# token = f'{head}.{payload}.{signtrue}'
# print(token)

# from ronglian_sms_sdk import SmsSDK
#
# accId = '2c94811c9035ff9f0192316fa00865e3'
# accToken = '357ef693d35b43a490536fcfe3528baa'
# appId = '2c94811c9035ff9f01923226669066cb'
#
# def send_message():
#     sdk = SmsSDK(accId, accToken, appId)
#     tid = '1'
#     mobile = '13898213749'
#     datas = ('7569', '3')
#     resp = sdk.sendMessage(tid, mobile, datas)
#     print(resp)

# send_message()

import oss2, uuid

# 阿里云oss存储    --   测试文件上传  --  图片

OSS_AccessKey_ID = 'LTAI5tAj98pFkHmf85sX7DNh'
OSS_AccessKey_Secret = '1Gt4XY3RrxCAPVaYVWEWLxXK61bXWF'
OSS_ENDPOINT = "oss-cn-beijing.aliyuncs.com"   # 访问域名
OSS_BUCKET_NAME = "fuguang719"  # 存储空间名称

# 创建存储空间的操作实例对象
# 认证
auth = oss2.Auth(OSS_AccessKey_ID, OSS_AccessKey_Secret)

bucket = oss2.Bucket(auth, OSS_ENDPOINT, OSS_BUCKET_NAME)
# https://fuguang719.oss-cn-beijing.aliyuncs.com/test/b00e775c-7c95-4642-82f2-eb7fc668a039.jpg
image_name = f'test/{str(uuid.uuid4())}.jpg'

# 查找一个文件（图片）
with open('E:\\sdd\\teacherImgs\\1.jpg', 'rb') as f:
    # 上传文件对象  --- 阿里云oss上传
    # 文件名，文件对象：流
    result = bucket.put_object(image_name, f.read())
    print('----------上传结果------------')
    print(result)
